package com.joker.demo.admin.router;


import com.joker.demo.admin.router.impl.ConsistentHashExecutorRouter;
import com.joker.demo.admin.router.impl.LeastFrequentlyUsedExecutorRouter;
import com.joker.demo.admin.router.impl.RandomExecutorRouter;
import com.joker.demo.admin.router.impl.RecentlyLeastUsedExecutorRouter;
import com.joker.demo.admin.router.impl.RoundRobinExecutorRouter;
import com.joker.demo.core.domain.enums.JobRoutePolicyEnum;

import java.util.HashMap;
import java.util.Map;

/**
 * @author : feixiang.li
 * @since : 2025-07-29 17:24
 */
public class ExecutorRouterFactory {

    private ExecutorRouterFactory() {

    }


    static Map<JobRoutePolicyEnum, ExecutorRouter> executorRouterMap = new HashMap<>(10);

    static {
        executorRouterMap.put(JobRoutePolicyEnum.DEFAULT, new RoundRobinExecutorRouter());
        executorRouterMap.put(JobRoutePolicyEnum.ROUND_ROBIN, new RoundRobinExecutorRouter());
        executorRouterMap.put(JobRoutePolicyEnum.RANDOM, new RandomExecutorRouter());
        executorRouterMap.put(JobRoutePolicyEnum.CONSISTENT_HASH, new ConsistentHashExecutorRouter());
        executorRouterMap.put(JobRoutePolicyEnum.LEAST_FREQUENTLY_USED, new LeastFrequentlyUsedExecutorRouter());
        executorRouterMap.put(JobRoutePolicyEnum.RECENTLY_LEAST_USED, new RecentlyLeastUsedExecutorRouter());
    }


    public static ExecutorRouter getExecutorRouter(JobRoutePolicyEnum jobRoutePolicyEnum) {
        return executorRouterMap.get(jobRoutePolicyEnum);
    }
}
